﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace XBoshiGFS.forms
{
    public partial class ImportHisDataFrom : Form
    {
        public ImportHisDataFrom()
        {
            InitializeComponent();
        }

        private void Step1_Click(object sender, EventArgs e)
        {

        }

        private void btnFileLocation_Click(object sender, EventArgs e)
        {
            openFileDialog1.Filter = "数据库文件|*.mdb|所有文件|*.*";
            openFileDialog1.FileName = "CAiTSLJ.mdb";
            if (openFileDialog1.ShowDialog()  == DialogResult.OK) {
                this.TBFileLocation.Text  = openFileDialog1.FileName ; 
           
            }
        }


        public String buildJDQGConnectString() {
            string strConnection = "Provider=Microsoft.Jet.OleDb.4.0;";
            strConnection += @"Data Source=" + this.TBFileLocation.Text;
            return strConnection;
        }
        public String buildWTKJConnectString()
        {
            string strConnection = "Provider=SQLOLEDB;server=127.0.0.1;database=water;uid=sa;pwd=sa";
            return strConnection;
        }

        private void btnStart_Click(object sender, EventArgs e)
        {
            if(radioButton2.Checked ){
                //交大启光
            ImportJDQGData source = new ImportJDQGData();
            source.ConnectionString = buildJDQGConnectString();

            Thread th = new Thread(new ThreadStart(source.BeginImport));
            //source.BeginImport();
            th.Start();
            var i=0;
            while (!source.IsFinished)
            {
                listBox1.Items.Insert(0,string.Format("{0}:{1}", DateTime.Now,source.GetCurrentStep() ));
                listBox1.Refresh(); 
                Thread.Sleep(5000);
            }
            MessageBox.Show("完成！");  
            }else{
            //沃泰科技
                ImportWTKJData source = new ImportWTKJData();
                source.ConnectionString = buildWTKJConnectString();

                Thread th = new Thread(new ThreadStart(source.BeginImport));
                //source.BeginImport();
                th.Start();
                var i = 0;
                while (!source.IsFinished)
                {
                    listBox1.Items.Insert(0, string.Format("{0}:{1}", DateTime.Now, source.GetCurrentStep()));
                    listBox1.Refresh();
                    Thread.Sleep(5000);
                }
                MessageBox.Show("完成！");  
            }
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close(); 
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }
    }
}
